package cn.com.server.common.util;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;

public class ApplicationContextUtil {
	private static final String APPLICATION_CONTEXT_KEY = "applicationContext";

	public static ApplicationContext getApplicationContext(JobExecutionContext context) throws Exception {
		ApplicationContext appCtx = null;
		appCtx = (ApplicationContext) context.getScheduler().getContext().get(APPLICATION_CONTEXT_KEY);
		if (appCtx == null) {
			throw new JobExecutionException("No application context available in scheduler context for key \""
					+ APPLICATION_CONTEXT_KEY + "\"");
		}
		return appCtx;
	}
}
